package com.qys.livesMall.app.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qys.livesMall.app.user.model.entity.H2AppUser;
import com.qys.livesMall.app.user.service.AppUserRelationService;
import com.qys.livesMall.app.user.service.IH2AppUserService;
import com.qys.livesMall.common.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户关系 前端控制器
 * </p>
 *
 * @author
 * @since 2023-10-13
 */
@RestController
@RequestMapping("/app/relation")
public class AppUserRelationController {

    @Autowired
    private AppUserRelationService relationService;

    @Autowired
    private IH2AppUserService userService;

    @PostMapping("/init")
    public R init(){
        long total=userService.count();
        for(long index=0;index<total;index++){
            LambdaQueryWrapper<H2AppUser> wq=new LambdaQueryWrapper<>();
            wq.last("limit "+index+",10");
            List<H2AppUser> users=userService.list(wq);
            for(H2AppUser user:users){
                relationService.init(Long.valueOf(user.getId()),user.getSuperior());
                System.out.println("用户："+user.getUserName()+"初始化完成");
            }
        }
        return R.ok();
    }
}
